package com.example.erat.controller;

import com.example.erat.common.Result;
import com.example.erat.entity.Experiment;
import com.example.erat.service.ExperimentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "实验管理接口")
@RestController
@RequestMapping("/experiment")
public class ExperimentController {

    @Autowired
    private ExperimentService experimentService;

    @ApiOperation("获取实验列表")
    @GetMapping("/list")
    public Result<List<Experiment>> getExperimentList(@RequestParam("courseId") String courseId) {
        List<Experiment> experiments = experimentService.getExperimentsByCourseId(courseId);
        return Result.success(experiments);
    }

    @ApiOperation("创建实验")
    @PostMapping("/create")
    public Result<String> createExperiment(@RequestBody Experiment experiment) {
        experimentService.save(experiment);
        return Result.success("创建成功");
    }
}    